package com.jkoss.wine.investment.service.impl;

import com.jkoss.common.util.CommonUtil;
import com.jkoss.wine.investment.entity.Investment;
import com.jkoss.wine.investment.entity.InvestmentFollow;
import com.jkoss.wine.investment.mapper.InvestmentFollowMapper;
import com.jkoss.wine.investment.mapper.InvestmentMapper;
import com.jkoss.wine.investment.service.IInvestmentFollowService;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 招商跟进记录 服务实现类
 * 
 * @Author Ning
 * @Version 1.0, 2018-10-26
 * @See
 * @Since com.jkoss.wine.investment.service.impl
 * @Description: TODO
 */
@Service
public class InvestmentFollowServiceImpl extends ServiceImpl<InvestmentFollowMapper, InvestmentFollow> implements IInvestmentFollowService {

	@Autowired
	private InvestmentMapper investmentMapper;

	@Override
	public Page selectVoPage(Page page, Wrapper wrapper) {
		SqlHelper.fillWrapper(page, wrapper);
		page.setRecords(baseMapper.selectVoPage(page, wrapper));
		return page;
	}

	@Override
	public boolean insertInvestmentFollow(InvestmentFollow entity) {
		Investment investment = investmentMapper.selectById(entity.getImid());
		// 状态：1-未联系[新增信息默认]、2-跟进中[只要有跟进记录即自动换成跟进中，普通帐号不设置修改权限]
		investment.setState(2);
		investment.setNtfw(CommonUtil.getDate(entity.getFwtm(), "@ISO6"));
		if (retBool(investmentMapper.updateById(investment))) {
			entity.setFwtm(CommonUtil.date6());
			return super.insert(entity);
		}
		return false;
	}

}
